/** ------------------------------------------------------------------------
 *	VisualGroup JavaScript prototype Classes, version 0.1
 *  (c) 2008 Bill Vison <vison_ruan@126.com>
 *
 *
/*--------------------------------------------------------------------------*/
using("Vsg.AuthorisingRule");

Vsg.AuthorisingRule.URLRule = Ext.extend(Vsg.AuthorisingRule,{
	


	constructor:function($config) {
		// ---- init variable ---
		Ext.apply(this , $config);
		Vsg.AuthorisingRule.URLRule.superclass.constructor.call(this, $config);
		this.on("afterLoadUrl" , this.doRule , this);
	},
	
	_getThisPage:function() {
		var $url = window.location.href;
		var $locationIndex = $url.lastIndexOf("/");
		$url = $url.substring($locationIndex+1);
		return $url;
	},
	

	doRule:function($authUrls) {
		var $returnRef = null;
		var $thisPage = this._getThisPage();

		// --- check the url is defined in registed ---
		var $authValid = false;
		try {
			// --- this url ---
			var $authUrl = null;
			for (var $i = 0 ; $i < $authUrls.length; $i++) {
				$authUrl = $authUrls[$i];
				var $authVal = $authUrl.controller.value;
				var $value = eval($authVal);
				
				if ( $thisPage.indexOf($authUrl.url) != -1 ) {
					if ($value == Vsg.AuthorisingRule.URLRule.Visitatorial) {
						$authValid = true;
						break;
					} else if ($value == Vsg.AuthorisingRule.URLRule.Invisitatorial) {
						throw new Vsg.AuthorisingRule.RuleException("该页面受权限保护，不允许访问该页面!" , null ,Vsg.AuthorisingRule.RuleException.NotAllowException);
					}
				}
			}
		} catch (ex) {
			throw ex;
		}
		

		
		// --- defined from super class pass status ----
		this._pass = $authValid;
	}
});

Vsg.AuthorisingRule.URLRule.xtype = "url";

Vsg.AuthorisingRule.URLRule.Visitatorial = 0;
Vsg.AuthorisingRule.URLRule.Invisitatorial = 1;

